/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package action.report;

import static com.opensymphony.xwork2.Action.SUCCESS;
import com.opensymphony.xwork2.ActionSupport;
import database.ReportDAO;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import model.*;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;

/**
 *
 * @author Trang
 */
@Namespace("/Administration/Revenue")
public class WRevenueByProductAction extends ActionSupport{
    
    private String startDate;
    private String endDate;
    private List<Revenuebyproduct> revenues = new ArrayList<Revenuebyproduct>();
    public ReportDAO reportDAO = new ReportDAO();
    private String date;
    private String title;
    private double totalAmount;

    public double getTotalAmount() {
        return totalAmount;
    }

    public void setTotalAmount(double totalAmount) {
        this.totalAmount = totalAmount;
    }
    
    

    public String getDate() {
        return date;
    }

    public void setDate(String date) {
        this.date = date;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }
     
    public String getStartDate() {
        return startDate;
    }

    public void setStartDate(String startDate) {
        this.startDate = startDate;
    }

    public String getEndDate() {
        return endDate;
    }

    public void setEndDate(String endDate) {
        this.endDate = endDate;
    }

    public List<Revenuebyproduct> getRevenues() {
        return revenues;
    }

    public void setRevenues(List<Revenuebyproduct> revenues) {
        this.revenues = revenues;
    }
    
    
    @Action(value = "revenuebyproduct", results = {
        @Result(name = "success", location = "/manageReport/w_revenue.jsp")   
    })
    public String RevenueByDate(){
        //products = inventoryDAO.getProductForInventory();  
        return SUCCESS;
    }
    
    @Action(value = "get-revenue", results = {
        @Result(name = "success", location = "/manageReport/w_revenuebyproduct.jsp")
    })
    public String RevenueBetween() throws ParseException{
        
        SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
        Date start = dateFormat.parse(startDate);
        Date end = dateFormat.parse(endDate);
        
        //System.out.println("Start"+start);
        //System.out.println("Issue"+issueDAO.getIssueByDate(startDate));
        revenues = reportDAO.getRevenueGroupbyProduct(start, end);
        
        date = "From "+startDate+" to "+endDate;
        title = "Total Revenue";
        totalAmount = 0;
        for(Revenuebyproduct item: revenues)
        {
            totalAmount += item.getTotalPrice();
        }
        return SUCCESS;
    }
}
